package applet;

import processing.core.PApplet;
import processing.core.PImage;

public class TabGroup {
	int tabCount;
	int currentTabIndex;
	float xPos, yPos;
	float width, height;
	float tagWidth, tagHeight;
	PImage[] selected, unselected;
	int[] tabColor;
	
	
	TabGroup(float x, float y, float w, float h, int n) {
		xPos = x;
		yPos = y;
		width = w;
		height = h;
		tabCount = n;
		selected = new PImage[tabCount];
		unselected = new PImage[tabCount];
		tabColor = new int[tabCount];
		currentTabIndex = 0;
	}
	
	void draw() {
		GLOBAL.processing.stroke(0);
		GLOBAL.processing.strokeWeight(1);
		//GLOBAL.processing.fill(tabColor[currentTabIndex]);
		GLOBAL.processing.fill(0);
		GLOBAL.processing.noTint();
		GLOBAL.processing.rect(xPos+tagWidth-1, yPos, width-tagWidth, height);
	}
	void drawAfterEverything() {	
		GLOBAL.processing.fill(0);
		GLOBAL.processing.noTint();
		GLOBAL.processing.imageMode(PApplet.CORNER);

		for(int i = 0; i < tabCount; i++) {
			if(i == currentTabIndex) {
				GLOBAL.processing.image(selected[i], xPos, yPos+i*tagHeight, tagWidth, tagHeight);
			}
			else {
				GLOBAL.processing.image(unselected[i], xPos, yPos+i*tagHeight, tagWidth, tagHeight);
			}
		}
	}
	
	boolean mousePressed() {
		if(GLOBAL.processing.mouseX > 0 && GLOBAL.processing.mouseX < tagWidth){
			for(int i = 0; i < tabCount; i++) {
				if(GLOBAL.processing.mouseY > i*tagHeight && GLOBAL.processing.mouseY < (i+1)*tagHeight) {
					if(currentTabIndex!=i) {
						if(currentTabIndex == 2) {	//current is map
							GLOBAL.map.saveZoomAndPan();
						}
						else if(i==2){	//next is map
							GLOBAL.map.loadZoomAndPan();
						}
					}
					currentTabIndex = i;
					return true;
				}
			}
		}
		return false;
	}

}
